﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataVirtualization;
using System.Windows;

namespace StudioEditorTest.CodeEditor
{
	public class CodeDataProvider : DependencyObject, IItemsProvider<CodeLine>
	{
		public static readonly DependencyProperty CountProperty = DependencyProperty.Register(
			"Count",
			typeof(int),
			typeof(CodeDataProvider),
			new FrameworkPropertyMetadata(0, CountDependencyValueChanged));

		private static void CountDependencyValueChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
		{
			CodeDataProvider provider = target as CodeDataProvider;
			provider.IsUpdated = true;
		}

		#region IItemsProvider<CodeLine> Members

		public IList<CodeLine> FetchRange(int startIndex, int count)
		{
			List<CodeLine> list = new List<CodeLine>();
			for (int i = startIndex; i < startIndex + count; i++)
			{
				if (i >= this.Count) break;
				CodeLine customer = new CodeLine();
				list.Add(customer);
			}
			return list;
		}

		public bool IsUpdated { get; set; }

		public int Count
		{
			get { return (int)GetValue(CountProperty); }
			set { SetValue(CountProperty,value); }
		}

		#endregion
	}
}
